#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=3e5+10;
ll m=0;
ll mm=0;
ll a[N];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n;
    cin>>n;
    ll sum=0;
    int pos=0;
    m=0;
    mm=0;
    int f=0;
    for(int i=0;i<n;i++)
    {
    	ll num=0;
    	scanf("%lld",&num);
    	if(num<0) f=1;
    	sum=sum+num;
    	
    	if(sum<m)
    	{
    		m=sum;
    		pos=i;
		}
		if(sum>mm)
		{
			mm=sum;
			if(f==0) m=mm;
		}
		a[i]=mm;
	}
	cout<<a[pos]<<endl;
	
	}
	

	return 0;
}

